package com.ctgu.examonline.controller;

import com.ctgu.examonline.entity.Teacher;
import com.ctgu.examonline.entity.User;
import com.ctgu.examonline.service.TeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/teacher")
public class TeacherController {

    @Autowired
    private TeacherService teacherService;

    //登录
    @CrossOrigin
    @RequestMapping("/login")
    public String login(@RequestBody User user){
        if(teacherService.login(user.getUsername(), user.getPassword()) != null){
            System.out.println(user.getUsername());
            return "ok";
        }else {
            return "false";
        }
    }

    //教师列表
    @RequestMapping("/list")
    public List<Teacher> list(){
        return teacherService.listTeacher();
    }

    //保存教师信息
    @RequestMapping("/add")
    public String save(Teacher teacher) {
        Teacher tea = new Teacher("TPOB", "123456", 20001001, "TPOB@163.com");
        teacherService.save(tea);
        return "add";
    }

    //删除
    @RequestMapping("/remove")
    public String remove(Integer tea_no) {
        teacherService.remove(60001022);
        return "remove";
    }

    //更新
    @RequestMapping("/update")
    public String update(Teacher teacher) {
        Teacher tea = new Teacher(60001026, "TPOB", "111111", null, "TPOB@163.com");
        teacherService.update(tea);
        return "update";
    }
}
